﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Layouts.Controls
{
    public partial class TradeHistoryTradeMarker : UserControl
    {
        #region Private Variables

            private DateTime tradeDate;
            private bool isBuy;
            private int id;

        #endregion

        #region Constructors

            public TradeHistoryTradeMarker(bool isBuy, int id, DateTime tradeDate) : this()
            {
                this.tradeDate = tradeDate;
                this.isBuy = isBuy;
                this.id = id;
                
                UpArrowId.Text = id.ToString();
                DownArrowId.Text = id.ToString();

                // Increase arrow width if the id is two digits
                if (id >= 10)
                {
                    UpArrowPath.Width = 18.546;
                    UpArrowReflection.Width = 18.546;
                    DownArrowPath.Width = 18.546;
                    DownArrowReflection.Width = 18.546;
                }

                // Set which arrow to show
                if (isBuy)
                {
                    UpArrow.Visibility = Visibility.Visible;
                    DownArrow.Visibility = Visibility.Collapsed;
                }
                else
                {
                    UpArrow.Visibility = Visibility.Collapsed;
                    DownArrow.Visibility = Visibility.Visible;
                }
            }

            public TradeHistoryTradeMarker()
            {
                InitializeComponent();
            }

        #endregion

        #region Get/Set Properties

            public DateTime TradeDate
            {
                get { return tradeDate; }
                set { tradeDate = value; }
            }

            public bool IsBuy
            {
                get { return isBuy; }
                set { isBuy = value; }
            }

            public int Id
            {
                get { return id; }
                set { id = value; }
            }

            public double Scale
            {
                get { return IconScale.ScaleX; }
                set 
                { 
                    IconScale.ScaleX = value;
                    IconScale.ScaleY = value;
                }
            }

        #endregion

        #region Event Handlers

            private void ArrowPath_MouseEnter(object sender, MouseEventArgs e)
            {
                this.Scale = 1.5;

                if (tradeMarkerEntered != null)
                {
                    tradeMarkerEntered(this, e);
                }

            }

            private void ArrowPath_MouseLeave(object sender, MouseEventArgs e)
            {
                this.Scale = 1;

                if (tradeMarkerExited != null)
                {
                    tradeMarkerExited(this, e);
                }

            }

        #endregion

        #region Events

            public event MouseEventHandler tradeMarkerEntered;
            public event MouseEventHandler tradeMarkerExited;

        #endregion

    }
}
